<?php ob_start(); ?>
<?php
$scriptWindowMsg = "
    $(function() {
        $('a#close').click(function() {
            window.close();
        });
    });";
$this->Html->scriptBlock($scriptWindowMsg, array('inline' => false));
?>
<style>
    .title-tbl {
        background-color: #dedddd;
        font-size: 13px;
        font-weight: bold;
    }
    thead {
      background-color: #dedddd;
    }
    td.tbl-broking {
        border-bottom: 1px solid #333333;
        border-left: 1px solid;
        border-right: 1px solid #333333;
        height: 30px;
    }
    .td-payment-r {
        width: 100px;
    }
    td {
        text-align: center;
        vertical-align: middle;
        border-color: #333333;
        border-style: solid;
        border-width: 1px;
        height: 30px;
    }
    .tbl-broking tr {
        height: 30px;
        margin: 0;
        padding: 0;
    }
    .tbl-broking-installerment {
        border-left: none;
        border-top: none;
        height: auto;
        margin: 0;
        padding: 0;
        table-layout: fixed;
        width: 100%;
    }
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }
    .clearfix:after {
        clear: both;
        content: ".";
        display: block;
        font-size: 0;
        height: 0;
        visibility: hidden;
    }
    .wrapper-table {
        height: auto;
        margin: 13px 0 0;
        padding: 0;
        width: 100%;
    }
    .clearfix {
        display: block;
    }
    .title-body-content {
        color: #A0002A;
        font-size: 17px;
        font-weight: bold;
        height: auto;
        margin: 0 0 0;
        padding: 0;
        text-align: center;
        width: 100%;
    }
    .wrapper-content-body {
        background-color: White;
        height: auto;
        margin: 0 0 60px;
        padding: 0 16px 0;
        width: 96.8%;
    }
    .hightlight {
        background-color: yellow;
        font-weight: bold;
    }
    .line-content-tbl {
        font-size: 12px;
    }
</style>
<div class="title-body-content"><?php echo $title_for_layout; ?></div>
<div class="wrapper-table clearfix" style="overflow: auto; padding-bottom: 10px; ">
    <?php
//    echo '<pre>';
//    print_r($trakingreports);die;
    foreach ($trakingreports AS $obj) {
    ?>   
    <table class="tbl-broking-installerment" style="margin-top: 30px;">
        <thead>
            <tr class="title-tbl" >
                <td><?php echo __('Reference#'); ?></td>
                <td><?php echo __('Payment#'); ?></td>
                <td><?php echo __('Installment#'); ?></td>
                <td><?php echo __('100% to AIH'); ?></td>
                <td><?php echo __('Amount'); ?></td>
                <td><?php echo __('Outstanding'); ?></td>
                
            <?php 
                $end = count($obj);
                $c = 1;
                $i = 0;
                foreach ($obj AS $installment) {
                    //php_debug($installment);
                    $checked = ($installment['Paymentschedule']['alltoaih'] == '1') ? '&#10003;' : ' ';
                    if($i == 0){
             ?> 
                     <?php
                    foreach ($installment['Paymentschedule']['arrmarket'] AS $key=>$value) {
                       echo '
                        <td> To ' . $value[0] . '</td>';
                    }
                    ?>
                        <td>To AIH Commission</td>
            </tr>
        </thead>
                    <tr>
                        <td rowspan="<?php echo $end; ?>">
                            <a href="<?php echo Router::url('/admin/accountresumes/edit/'.$installment['Paymentschedule']['accid'], true); ?>" target="blank">
                                <?php echo $installment['Paymentschedule']['refid_edit'] ?>
                            </a>
                        </td>
                    <?php 
                    }else{
                    ?>    
                        <tr>
                    <?php        
                    }
                    ?>    
                        <td>
                                <?php echo $installment['Paymentschedule']['refid']; ?>
                        </td>
                        <td>
                                <?php echo $installment['Paymentschedule']['installment']; ?>
                        </td>
                        <td>
                                <?php 
                                    echo $checked; 
                                ?>
                        </td>
                        <td class="hightlight" style="text-align: right; padding-right:3px;">
                                <?php echo $installment['Paymentschedule']['currency'].' '.number_format($installment['Paymentschedule']['broker_amount'],2); ?>
                        </td>
                        <td class="hightlight" style="text-align: right; padding-right:3px;">
                                <?php echo $installment['Paymentschedule']['currency'].' '.number_format($installment['Paymentschedule']['outstanding'],2); ?>
                        </td>
                        
                        <?php
                        //php_debug($installment);
                        $arrpaid = $installment['Paymentschedule']['arrmarketpaid'];
                        foreach ($installment['Paymentschedule']['arrmarket'] AS $key=>$value) {
                            $checked = '';
                            if($arrpaid != null){
                                if($arrpaid[$key]['paid'] == 'on'){
                                    $checked = '&#10003;';
                                }
                            }
                            echo '<td>' . $checked . '</td>';
                        }
                        ?>
                        <td>
                                <?php 
                                if($installment['Paymentschedule']['paid_to_aih'] == 1){
                                    $checked = '&#10003;';
                                }else{
                                    $checked = '';
                                }
                                echo $checked;
                                ?>
                        </td>
                    </tr>
        <?php 
        $i++;
        } 
        ?>
    </table>
    <?php 
    } 
    ?>
</div>
<?php
    $HtmlCode= ob_get_contents();
    ob_end_flush();
    $file = '/home/johnso28/public_html/aihreinsurance.com/dompdf/aih/installment_tracking_report.html';
    $HtmlCode1 = str_replace('&#10003;', '<img src="img/tick.gif" alt="" />', $HtmlCode);
    file_put_contents($file, $HtmlCode1);
?>

<div class="wrapper-button-form clearfix">
    <div class="button-form clearfix">
        <div class="button-aihre button-blue"><a href="JavaScript:void(0)" title="CLOSE" id="close"><?php echo __('CLOSE'); ?></a></div>
    </div>
</div>
<div class="wrapper-button-form clearfix">
    <div class="button-form clearfix">
        <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/dompdf/dompdf.php?base_path=aih/&input_file=installment_tracking_report.html&paper=a4">Download PDF</a>
        &nbsp; | &nbsp;
		<?php echo $this->Html->link('Download Excel', '/phpexcel/installmenttracking.php?ids=' . $ids, null, array()); ?>
    </div>
</div>